package com.zkingsoft.actions.admin.web;

import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.constraint.BaseController;
import javax.annotation.Resource;
import com.zkingsoft.anotations.RemoveRequestToken;
import com.zkingsoft.services.web.WebMsgService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.zkingsoft.anotations.SaveRequestToken;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.util.WebUtil;
import com.zkingsoft.authority.MatrixAdapter;
import com.zkingsoft.model.web.WebMsg;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2017-01-11 13:38
 */
@Controller
@RequestMapping(value = "admin/webMsg")
public class WebMsgController extends BaseController{

	@Resource
	private WebMsgService webMsgService;
	
	@Resource
	private MatrixAdapter matrixAdapter;
	
	
	
	//记录编辑前的值Before_Edit_Value
	public static final String BEV="WebMsg_BEV";
	
	public static final String fnCode = "WebMsg";
	public static final String search = fnCode + ":search";
	public static final String edit = fnCode + ":edit";
	public static final String del = fnCode + ":del";
	public static final String add = fnCode + ":add";
	
	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(WebMsg webMsg, PaginationVO pageVo) {
		matrixAdapter.isBtnPermitted(search);
		return showList(webMsgService, webMsg, pageVo);
	}
   	
	/**
	 * 新增或者修改页面
	 */   
	@RemoveRequestToken	
   	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(WebMsg webMsg) {
		if (webMsg.getMsgId() != null) {
	   		matrixAdapter.isBtnPermitted(edit);
	   		webMsg.setMsgId(((WebMsg)WebUtil.getSessionAttribute(BEV)).getMsgId());
	   		AjaxResult result=modify(webMsgService, WebUtil.getSessionAttribute(this.BEV), webMsg, "webMsg");
			WebUtil.removeSessionAttribute(this.BEV);
			return  result;
		} else {
			matrixAdapter.isBtnPermitted(add);
			return add(webMsgService, webMsg, "webMsg");
		}
	}
	
   	/**
	 * 进入修改界面
	 */   
	@SaveRequestToken
   	@RequestMapping(value = "/editForm")
	public String editForm(Long id) {
		matrixAdapter.isBtnPermitted(edit);
		WebMsg webMsg;
		if (id != null) {
			webMsg = webMsgService.findById(id);
			WebUtil.getRequest().setAttribute("obj", webMsg);
			WebUtil.setSessionAttribute(this.BEV, webMsg);
		}
		return "admin/webMsg-form";
	}
   	
   	
   	/**
	 * 删除
	 */  
 	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		matrixAdapter.isBtnPermitted(del);
		return remove(webMsgService, keys);
	}
  
}